package cn.tedu.weibo.controller;

import cn.tedu.weibo.common.response.JsonResult;
import cn.tedu.weibo.pojo.dto.WeiboDTO;
import cn.tedu.weibo.pojo.vo.WeiboDetailVO;
import cn.tedu.weibo.pojo.vo.WeiboIndexVO;
import cn.tedu.weibo.service.IWeiboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/weibos")
public class WeiboController {

    @Autowired
    private IWeiboService weiboService;

    @PostMapping("add-new")
    public JsonResult addNew(@RequestBody WeiboDTO weiboDTO){
        System.out.println("----222-----"+weiboDTO);
        weiboService.addNew(weiboDTO);
        return JsonResult.ok();
    }

    @GetMapping("index")
    public JsonResult selectIndex(){
        List<WeiboIndexVO> list = weiboService.listForIndex();
        return JsonResult.ok(list);
    }
    @GetMapping("{id}")
    public JsonResult detailById(@PathVariable Long id){
        WeiboDetailVO weiboDetailVO = weiboService.selectById(id);
        return JsonResult.ok(weiboDetailVO);
    }


}
